Welcome back.
That last project was a little bit overwhelming because we used a ton of libraries and a lot of data
visualizations that are very specific to a library.
But we haven't really touched the topic of training the data and creating models.
So in this project, we're actually going to do some machine learning.
It's going to be a lot of fun.
But I want to give you a warning.
This is just a taste of what machine learning is like.
If this is your first time, it might seem a little bit overwhelming, but just like with anything,
it's all about practice and repetition.
But hopefully by the end of it, you will see this six step process and how it actually works.
And at the end of the day, you'll also realize that it's not maybe as complicated as you might have
initially thought.
So let's get started.
The first thing we're going to do is create a new notebook with Python three.
Now, this time around, we're going to use a different data set and a famous one when it comes to machine
learning.
It's called the iris data set for the iris flower.
So if I type in iris flower.
It's a data set that has all this information about the iris flower that actually has different types.
So we're going to create a machine learning model that can detect types of the iris plant.
Now, luckily for us.
We can access this data very, very easily using a psychic learn.
So I could learn, if you remember, was another library that is really, really powerful to help us
with machine learning.
So all we have to do is say from psychic learn dot.
Data sets and a psychic learn comes pre-built with some good data sets that you can explore on your
own.
And we're just going to import the iris data set or lowercase i.
Just like this.
So that if I do, iris equals load.
Dot.
Iris.
Just like this.
And I click run.
Oh, and this should be an underscore.
So we now have the data loaded.
And if we go back to our report, we've imported the data.
We don't need to clean the data.
We learned about that in the previous project.
But because CI could learn has these data pre-built, we can assume that it's clean data that we can
use in our models.
The next step is to split the data into training, set and test set.
But in order for us to do that, we can use this concept of X and Y in machine learning.
So X, this capital x usually means the inputs that we want to give to our machine learning model.
So in our case, we'll say iris dot data will be our inputs.
So that is the data that we get.
So let's actually see what that is.
Let's run.
That's the data.
You see that?
It's just some massive arrays.
And why is going to be the target.
So if I do dot target and I click run.
You'll see that this is the target.
Now, what this means is we want to find or create a function that takes an X, which will be our data.
And outputs the Y.
Which is the target.
That is the answer.
Now, in our case, these are the answers, zero one and two.
But if I Google iris data set.
And I go to the Wikipedia page here.
You'll see that the there are three types of iris, the cytosol versus color and Virginia.
And each one of these is represented by either zero one or two.
So if we look at our data set.
This target is the types of those three iris flower types.
So the target in this case that comes pre set with the cyclone library is this is the data of the images.
So again, if I remove this and hit run, this is the image.
So each list is.
A piece of data that represents, by some parameters, the iris flower.
And then we have the target, which is the answer is when we input this data, what is the output?
Which one of the three flowers is it?
Now if I go to Kaggle.
And I actually type in the iris.
Data set.
You can see that the columns are while the length of the pedal, the length, and then the species name.
So you can see here that these are the columns that it's testing for.
And you can see these are the numbers that we get in that array and each one corresponds with different
type of the iris flower.
So let's get back to that.
I'm going to say that Capital X is going to be our data, our input.
And then y, lowercase y.
And this is just a standard.
We'll be our target.
Finally we actually want to get the feature name.
So each item in the list here is a feature.
Remember, that's what.
These columns are.
These columns are the width, the length of the petal and the couple.
So we can store that by simply saying feature.
Names.
As the iris.
Dot.
Feature names.
Again, which comes pre-built with the iris data set, and then the target names will be the iris dot
target names.
Again if I run this.
Let's do feature names first.
There's the columns.
And if I do target names.
You see that these are the three options.
So up until now, we've imported the data.
We didn't have to clean the data.
We haven't really split the data yet, but we're at least starting to understand our data and perhaps
what it contains.
So once we've understood the data and knowing that we have this information, we can now start splitting
the data into a training and data set, because right now we're doing supervised learning because these
are labeled, right?
We have all the data that we need and we also have the answers that we need so we can test our model.
By the way, before I show you how to split the data, what do you think?
The type?
Of X is.
Can you guess?
It's a numpy array.
Remember that library numpy that I told you allows us to use multi dimensional arrays?
Well, underneath the hood, this data set is a numpy array.
It's a little bit more feature rich than just a python list.
Anyway, let's start to split our data.
So what we want to do here is from the Psych Learn library.
I want to grab the model selection.
And in here we're going to import.
The train test split.
Now.
What is that?
Let's Google and find out.
So again, if I go to the library documentation, you can see that the train test split simply splits
array or matrices into random train and test subsets.
So just randomly decides for us how it's going to split the data into the training data and the test
data.
So now we can use it in an interesting way.
We can simply say X is the training data set the x.
Test data, set the why train data set and then the Y test data set.
And again, we can just assign that to variables by using the train.
Test split.
Function that we import.
And give it the X, the Y and some different variables.
So, for example, over here, if you can see.
We have things like test size or random state or shuffle different variables that we want.
Again, you can read this on your own.
In our case, let's just say that the test size will be 0.4.
Now let's have a look at what kind of data we have now.
So if I do print X the train data and we can do a dot shape here.
And we'll also print the.
Test shape.
If I run this.
It returns what we call a dimensionality of the array.
So that is how many rows and columns.
So it's got four columns and 90 rows.
So our train data has 90 rows and our task test data has 60 rows.
If I change the test size here to point five and I click run, you see that?
Now I'm splitting the test size between 50% being for train, 50 for test so we can actually change
things up and try different things.
And manipulate the train and test data size.
Ideally, though, we want to have more train data than tests just because remember, the more data
we have, the better our model is going to get.
And this is going to be the same for the Y train and the Y test variables as well.
Congratulations.
We've just split the data into training set and test set.
We now have some exciting steps ahead, such as creating the model.
Let's take a break and learn how to do that in the next video.